package com.hh.erp.util.excel;


import com.alibaba.excel.EasyExcel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Excel 工具类
 */
@Slf4j
public class ExcelUtil implements Serializable {

    public static <T> List<T> readExcel(MultipartFile file, Class<T> clz){

        if(file == null) {
            log.error("file == null");
            return null;
        }
        if(clz == null) {
            log.error("clz == null");
            return null;
        }
        List<T> list = null;
        try {
            list = EasyExcel.read(file.getInputStream())
                    .head(clz.getClass())
                    .sheet()
                    .doReadSync();
        }
        catch (Exception e) {
            e.getStackTrace();
            log.error("error: "+e.getMessage());
        }
        return list;
    }
}
